package work;

public class test2 {
	public static final Object lock=new Object();
	public static void main(String[] args) {
        for (int j = 0; j < 3; j++) {
            Worker so = new Worker();
            Mworker mo = new Mworker();
            so.start();
            mo.start();
        }
    }    
    static class Mworker extends Thread {
    	@Override
        public void run() {
            synchronized (lock) {
                for (int i = 0; i < 5; i++) {
                    System.out.println("主程序: " + i);
                }
                lock.notify();
                try {
					lock.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}		 
            }
        }
    }


    static class Worker extends Thread {
        @Override
        public void run() {
            synchronized (lock) {
                for (int i = 0; i < 3; i++) {
                    System.out.println("子程序: " + i);
                }
                lock.notify();
                try {
					lock.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
            }
        }
    }
}
